<?php
session_start();
require_once __DIR__.'/../../utils/checkTokenUtils.php';
require_once __DIR__ . '/../../model/UserModel.php';
use model\UserModel;

// 获取要删除的用户ID
$userId = isset($_POST['id']) ? (int)$_POST['id'] : 0;

if ($userId > 0) {
    $userModel = new UserModel();
    $result = $userModel->deleteUser($userId);
    if ($result) {
        $_SESSION['success_message'] = '用户删除成功！';
    } else {
        $_SESSION['error_message'] = '用户删除失败，请重试。';
    }
} else {
    $_SESSION['error_message'] = '无效的用户ID。';
}

// 重定向回用户列表页面
header('Location: Users.php');
exit();